//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "OneDayCounter.h"
using namespace Cephei::QL::Times::Daycounters;
#include <gen/QL/Times/DayCounter.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter () : CDayCounter(COneDayCounter::typeid)
{
    try
    {
#ifdef HANDLE
        _phOneDayCounter = NULL;
#endif
        _ppOneDayCounter = new boost::shared_ptr<QuantLib::OneDayCounter> (new QuantLib::OneDayCounter ( ));
        SetDayCounter (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (boost::shared_ptr<QuantLib::OneDayCounter>& childNative, Object^ owner) : CDayCounter(COneDayCounter::typeid)
{
#ifdef HANDLE
	_phOneDayCounter = NULL;
#endif
	_ppOneDayCounter = &childNative;
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
}
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (QuantLib::OneDayCounter& childNative, Object^ owner) : CDayCounter(COneDayCounter::typeid)
{
#ifdef HANDLE
	_phOneDayCounter = NULL;
#endif
	_ppOneDayCounter = new boost::shared_ptr<QuantLib::OneDayCounter> (&childNative);
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
    _OneDayCounterOwner = owner;
    _DayCounterOwner = owner;
}

Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (COneDayCounter^ copy) : CDayCounter(COneDayCounter::typeid)
{
#ifdef HANDLE
	_phOneDayCounter = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppOneDayCounter = new boost::shared_ptr<QuantLib::OneDayCounter> (copy->GetShared());
        _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
    }
}
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (System::Type^ t) : CDayCounter(COneDayCounter::typeid)
{
#ifdef HANDLE
	_phOneDayCounter = NULL;
#endif
	if (!t->IsSubclassOf(COneDayCounter::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (QuantLib::Handle<QuantLib::OneDayCounter>& childNative, Object^ owner)  : CDayCounter(COneDayCounter::typeid)
{
	_phOneDayCounter = &childNative;
	_ppOneDayCounter = &static_cast<boost::shared_ptr<QuantLib::OneDayCounter>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
    _OneDayCounterOwner = owner;
}
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (QuantLib::Handle<QuantLib::OneDayCounter> childNative)  : CDayCounter(COneDayCounter::typeid)
{
	_phOneDayCounter = &childNative;
	_ppOneDayCounter = &static_cast<boost::shared_ptr<QuantLib::OneDayCounter>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Daycounters::COneDayCounter::COneDayCounter (QuantLib::OneDayCounter childNative)  : CDayCounter(COneDayCounter::typeid)
{
#ifdef HANDLE
	_phOneDayCounter = NULL;
#endif
	_ppOneDayCounter = new boost::shared_ptr<QuantLib::OneDayCounter> (new QuantLib::OneDayCounter (childNative));
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppOneDayCounter));
}
#endif

Cephei::QL::Times::Daycounters::COneDayCounter::~COneDayCounter ()
{
    if (_ppOneDayCounter != NULL)
    {
	    delete _ppOneDayCounter;
        _ppOneDayCounter = NULL;
    }
}
Cephei::QL::Times::Daycounters::COneDayCounter::!COneDayCounter ()
{
    if (_ppOneDayCounter != NULL)
    {
	    delete _ppOneDayCounter;
    }
}
QuantLib::OneDayCounter& Cephei::QL::Times::Daycounters::COneDayCounter::GetReference ()
{
    if (_ppOneDayCounter == NULL) throw gcnew NativeNullException ();
	return **_ppOneDayCounter;
}
boost::shared_ptr<QuantLib::OneDayCounter>& Cephei::QL::Times::Daycounters::COneDayCounter::GetShared ()
{
    if (_ppOneDayCounter == NULL) throw gcnew NativeNullException ();
	return *_ppOneDayCounter;
}
QuantLib::OneDayCounter* Cephei::QL::Times::Daycounters::COneDayCounter::GetPointer ()
{
    if (_ppOneDayCounter == NULL) throw gcnew NativeNullException ();
	return &**_ppOneDayCounter;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::OneDayCounter>& Cephei::QL::Times::Daycounters::COneDayCounter::GetHandle ()
{
	if (_phOneDayCounter == NULL)
	{
		_phOneDayCounter = new Handle<QuantLib::OneDayCounter> (*_ppOneDayCounter);
	}
	return *_phOneDayCounter;
}
#endif
bool Cephei::QL::Times::Daycounters::COneDayCounter::HasNative () 
{
	return (_ppOneDayCounter != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Daycounters::IOneDayCounter^ Cephei::QL::Times::Daycounters::COneDayCounter_Factory::Create ()
{
    return gcnew COneDayCounter ();
}
